Skip to content

FIX Preserve user message structure in generic system squash#1505

Merged
jbolor21 merged 10 commits into
microsoft:mainfrom
biefan:preserve-multipart-generic-system-squash
Jun 10, 2026
Merged

FIX Preserve user message structure in generic system squash#1505
jbolor21 merged 10 commits into
microsoft:mainfrom
biefan:preserve-multipart-generic-system-squash

Conversation

@biefan

@biefan biefan commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • squash the first system message into the first user message instead of rewriting whichever message happens to come second
  • preserve multipart user messages when squashing system instructions into user content
  • add regression coverage for assistant-before-user conversations and multipart user messages

Problem

GenericSystemSquashNormalizer currently assumes messages[1] is the user message and rebuilds it with Message.from_prompt(). That causes two issues:

  • assistant messages that appear before the first user message get rewritten as user
  • multipart user messages lose non-text pieces when the normalizer collapses them into a single text prompt

Validation

  • .venv/bin/pytest tests/unit/message_normalizer -q
  • .venv/bin/ruff check pyrit/message_normalizer/generic_system_squash.py tests/unit/message_normalizer/test_generic_system_squash_normalizer.py

@jbolor21 jbolor21 enabled auto-merge May 1, 2026 17:38
@romanlutz romanlutz changed the title Preserve user message structure in generic system squash FIX Preserve user message structure in generic system squash May 2, 2026
Comment thread pyrit/message_normalizer/generic_system_squash.py Outdated
Roman Lutz added 2 commits June 5, 2026 13:14
…o marks

Merge instructions into the first text piece (or prepend an instruction-only
text piece when none exists) so non-text pieces such as images are preserved
in their original positions with their original data types.

Also remove `@pytest.mark.asyncio` from the new tests since `asyncio_mode`
is set to `auto` for the project.

Co-authored-by: Copilot <[email protected]>
…neric-system-squash

# Conflicts:
#	tests/unit/message_normalizer/test_generic_system_squash_normalizer.py
…neric-system-squash

# Conflicts:
#	pyrit/message_normalizer/generic_system_squash.py
#	tests/unit/message_normalizer/test_generic_system_squash_normalizer.py
@jbolor21 jbolor21 added this pull request to the merge queue Jun 10, 2026
Merged via the queue into microsoft:main with commit b532083 Jun 10, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants